//
//  MONoticeViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/1.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MONoticeViewCell.h"

@interface MONoticeViewCell ()

@property(nonatomic,strong)TYAttributedLabel *nameLabel;

@property(nonatomic,strong)UILabel *dateLabel;

@property(nonatomic,strong)UILabel *comeLabel1;

@property(nonatomic,strong)UILabel *comeLabel2;

@end

@implementation MONoticeViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MONoticeViewCell";
    MONoticeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MONoticeViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    self.nameLabel = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(14, 20, SCREEN_WIDTH - 28, 1)];
    self.nameLabel.font = FONT_SIZE(16);
    self.nameLabel.textColor = KBlackColor_222222;
    self.nameLabel.numberOfLines = 0;
//    self.nameLabel.backgroundColor = [UIColor redColor];
    [self addSubview:self.nameLabel];
    
    
    self.comeLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(14, self.nameLabel.bottom + 17, SCREEN_WIDTH-28, 13)];
    self.comeLabel1.font = FONT_SIZE(12);
    self.comeLabel1.textColor = KBlackColor_919395;
    [self addSubview:self.comeLabel1];
    
    self.comeLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(14, self.comeLabel1.bottom + 6, SCREEN_WIDTH-28, 13)];
    self.comeLabel2.font = FONT_SIZE(12);
    self.comeLabel2.textColor = KBlueColor_2C94FF;
    [self addSubview:self.comeLabel2];
    
    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH- 14 - (SCREEN_WIDTH-28), self.comeLabel2.y, SCREEN_WIDTH-28, 13)];
    self.dateLabel.font = FONT_SIZE(12);
    self.dateLabel.textAlignment = NSTextAlignmentRight;
    self.dateLabel.textColor = KBlackColor_919395;
    //    self.dateLabel.backgroundColor = [UIColor redColor];
    [self addSubview:self.dateLabel];
    
    
    UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(clickTap)];
    [self addGestureRecognizer:longTap];
}

-(void)clickTap
{
    if (self.clickLongTapBlock) {
        self.clickLongTapBlock();
    }
}

+(CGFloat)heightForMONoticeViewCellAndModel:(MONoticeModel *)model
{
    NSString *lineStr = @"";
    NSString *textType = @"";
    if (model.wdlx.length>0) {
        lineStr = @"  ";
        textType = @"发文";
    }else{
        lineStr = @"";
        textType = @"";
    }
    
    if ([model.depthDo integerValue]==4) {//局内
        
        CGFloat H = 0;
        H += 20;
        
        CGSize size = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@  %@%@",model.nameStr,textType,lineStr] WithFont:FONT_SIZE(16) MaxSize:CGSizeMake(SCREEN_WIDTH - 28, MAXFLOAT)];
        CGFloat height = size.height;
        if (height>20) {
            height +=15;
        }
        H += height;
        
        H += 13*2;
        
        H += 18;
        
        return H;
        
    }else{
        
        CGFloat H = 0;
        H += 20;
        
        CGSize size = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@  %@%@",model.nameStr,textType,lineStr] WithFont:FONT_SIZE(16) MaxSize:CGSizeMake(SCREEN_WIDTH - 28, MAXFLOAT)];
        CGFloat height = size.height;
        if (height>20) {
            height +=15;
        }
        H += height;
        
        H += 17;
        
        H += 13*2;
        
        H += 6;
        
        H += 17;
        
        return H;
    }
    
}

-(NSMutableAttributedString *)attAtr:(NSString *)contentStr subStr:(NSString *)subStr
{
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
    
    //总体的颜色和大小
    NSRange range = NSMakeRange([contentStr rangeOfString:subStr].location, [contentStr rangeOfString:subStr].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:KBlackColor_919395 range:range];
    
    return noteStr;
}

-(void)setModel:(MONoticeModel *)model
{
//    self.nameLabel.text = model.nameStr;
    if ([model.typeStr integerValue]==1) {
        self.nameLabel.textColor = KBlackColor_919395;
    }else{
        self.nameLabel.textColor = KBlackColor_222222;
    }
    
    NSString *textType = @"";
    NSString *lineStr = @"";
    UIColor *sunBackCol0r;
    UIColor *contentColor;
    if ([model.typeStr integerValue]==1) {//已读
        sunBackCol0r = KBlackColor_919395;
        contentColor = KBlackColor_919395;
    }else{
        sunBackCol0r = KRedColor_FF4040;
        contentColor = KBlackColor_222222;
    }
    if (model.wdlx.length>0) {
        if ([model.wdlx isEqualToString:@"收文处理单"]) {
            textType = @"收文";
        }else if ([model.wdlx isEqualToString:@"公告审批表"]){
            textType = @"公告";
        }else{
            textType = @"发文";
        }
        lineStr = @"  ";
    }else{
        textType = @"";
        lineStr = @"";
    }
    
    self.nameLabel.textContainer = [NSString stringWithContentStr:[NSString stringWithFormat:@"%@%@",lineStr,model.nameStr] contentColor:contentColor contentFont:16 rangeStr:textType rangBackgroundColor:sunBackCol0r rangeFont:9 rangeCorner:13/2 rangeRectCorner:UIRectCornerBottomLeft | UIRectCornerTopLeft | UIRectCornerTopRight withViewWidth:SCREEN_WIDTH-28];
    [self.nameLabel sizeToFit];
    
    self.dateLabel.text = model.dateStr;
    
    self.comeLabel1.text = model.comeNumberStr;
    
    self.comeLabel2.text = model.comeStr;
    
    CGSize size = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@  %@%@",model.nameStr,textType,lineStr] WithFont:FONT_SIZE(16) MaxSize:CGSizeMake(SCREEN_WIDTH - 28, MAXFLOAT)];
    
    CGFloat height = size.height;
    if (height>20) {
        height +=15;
    }
    self.nameLabel.height = height;
    

    if ([model.depthDo integerValue]==4) {//局内
        self.comeLabel1.y = self.nameLabel.bottom + 13;
        self.dateLabel.y = self.comeLabel1.y;
    }else{
        self.comeLabel1.y = self.nameLabel.bottom + 17;
        self.comeLabel2.y = self.comeLabel1.bottom + 6;
        self.dateLabel.y = self.comeLabel2.y;
    }
    
    
}




@end
